package com.web.controller.user;

import com.core.dto.UserDTO;
import com.core.shared.ValidateCodeHandle;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * User: xf
 * Date: 2016/4/19
 * Time: 21:05
 * To change this template use Editor | File and Code Templates.
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping(value = "login", method = RequestMethod.GET)
    public ModelAndView login(HttpServletRequest request, Model model) {
        Random random = new Random();
        int code = random.nextInt(9000) + 1000;
        ValidateCodeHandle.save(request.getSession().getId(), String.valueOf(code));
        model.addAttribute("validate_code", code);
        return new ModelAndView("login", "userDTO", new UserDTO());
    }


}
